import routes from 'virtual:generated-pages';
import { createRouter, createWebHashHistory } from 'vue-router';

console.table(routes);

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

const userLoginToken = 'userLoginTooken';

const whiteRoutes = ['index', 'userRegisterPassword', 'userRegisterPhone', 'agreementsService', 'agreementsPrivacy']

router.beforeEach((to, from, next) => {
    (from.name && whiteRoutes.includes(from.name.toString()) || from.name == void 0)
        ? (
            (to.name && !whiteRoutes.includes(to.name.toString()) || to.name == void 0)
                ? (asyncGetCookie(userLoginToken).then((response) => { (response && response.token) ? next() : next({ name: 'index' }) }))
                : (asyncGetCookie(userLoginToken).then((response) => { (response && response.token) ? next({ name: 'home' }) : next() }))
        ) : (
            (to.name && !whiteRoutes.includes(to.name.toString()) || to.name == void 0)
                ? (asyncGetCookie(userLoginToken).then((response) => { (response && response.token) ? next() : next({ name: 'index' }) }))
                : (asyncGetCookie(userLoginToken).then((response) => { (response && response.token) ? next({ name: 'index' }) : next() }))
        )
});

export default router;
